<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>XX系统 - 房屋信息管理</title>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/main.css">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/lib/font-awesome/css/font-awesome.css">
</head>

<body>
<div class="box">
	<h3>用户管理<a href="${pageContext.request.contextPath}/css/main.css"></a></h3>
	<div class="actions">
		<div>
			<a class="btn btn-primary" href="${pageContext.request.contextPath}/view/user/add.jsp">添加用户</a>
			<input class="btn btn-primary" type = "button" value = "删除所选中的" onclick="fun()">
		</div>
	</div>
   <br/>
	
	<tr>
	<form action = "${pageContext.request.contextPath}/UserFindxxxServlet">
	<select name = "filedName">
	<option value = "u_sex">u_sex</option>
	<option value = "u_realname">u_realname</option>
	<option value = "role_id">role_id</option>
	</select>
	<input type = "text" name = "filed" >
	 <input type = "submit" value = "查询">
	 </form>
	 <br/>
	 </tr>
	 <table class="list">
	 	<form action = "${pageContext.request.contextPath}/UserMFindServlet">
	 		性别：<input type = "text" name = "sex" >
	 		名字：<input type = "text" name = "realname" >
	 		用户类别：<input type = "text" name = "role" >
	 		<input type = "submit" value = "查询">
		 </form>
		<tr>
			<th>选择</th>
			<th>序号</th>
			<th>用户账号</th>
			<th>用户密码</th>
			<th>用户姓名</th>
			<th>用户性别</th>
			<th>用户类别</th>
			<th>创建时间</th>
			<th>账号状态</th>
			<th>用户操作</th>
		</tr>
		<c:forEach  items="${pb.beanList}"  var="user">
		<tr>
			<td><input type = "checkbox" name = "u_user" value = "${user.u_id}"></td>
			<td>${user.u_id}</td>
			<td>${user.u_name}</td>
			<td>${user.u_pass}</td>
			<td>${user.u_realname}</td>
			<td>${user.u_sex}</td>
			<td>${user.role_id}</td>
			<td>${user.u_create_time}</td>
			<td>${user.u_state}</td>
			<td>
				<a class="fa fa-info" title="详情" href="#"></a>
				&nbsp;&nbsp;
				<a class="fa fa-pencil" title="编辑" href="${pageContext.request.contextPath}/UserUpdServlet?u_id=${user.u_id}"></a>
				&nbsp;&nbsp;
				<a class="fa fa-remove" title="删除" href="${pageContext.request.contextPath}/UserDelServlet?u_id=${user.u_id}" onclick="confirmDelete(1)"></a>
			</td>
		</tr>
		</c:forEach>
	</table>
	<div class="pager-info">
		<div>共有 ${pb.tr } 条记录，第 ${pb.pc }/${pb.tp } 页 </div>
		<div>
			<ul class="pagination">
				<li class="paginate_button previous disabled }">
				<c:if test = "${pb.pc>1 }" >
				<a href="${pb.url }&pc=1">首页</a>
				</c:if>
				</li>
				<li class="paginate_button previous disabled }">
				<c:if test = "${pb.pc>1 }" >
				<a href="${pb.url }&pc=${pb.pc-1 }">上一页</a>
				</c:if>
				</li>
				<c:choose>
					<c:when test="${pb.pc<3 }">
						<c:set var = "begin" value = "1"></c:set>
						<c:set var = "end" value = "${pb.tp }"></c:set>
					</c:when>
					<c:otherwise>
						<c:set var = "begin" value = "${pb.pc-1 }"></c:set>
						<c:set var = "end" value = "${pb.pc+1 }"></c:set>
						<c:if test="${pb.pc-1<1 }">
						<c:set var = "begin" value = "1"></c:set>
						<c:set var = "end" value = "3"></c:set>
						</c:if>
						<c:if test="${pb.pc+1>pb.tp }">
						<c:set var = "begin" value = "${pb.tp-2 }"></c:set>
						<c:set var = "end" value = "${pb.tp }"></c:set>
						</c:if>	
					</c:otherwise>
					
				</c:choose>
				
				<c:forEach var = "i" begin = "${begin }" end = "${end }">
					<c:choose>
						<c:when test="${pb.pc == i }">
							<li class="paginate_button active"><a href = "#">${i }</a></li>
						</c:when>
						<c:otherwise>
							<li class="paginate_button next disabled"><a href="${pb.url }&pc=${i }">${i }</a></li>
						</c:otherwise>
					</c:choose>
				</c:forEach>
				
				<li class="paginate_button next disabled">
				<c:if test = "${pb.pc<pb.tp }" >
				<a href="${pb.url }&pc=${pb.pc+1 }">下一页</a>
				</c:if>
				</li>
				<li class="paginate_button next disabled">
				<c:if test = "${pb.pc<pb.tp }" >
				<a href="${pb.url }&pc=${pb.tp }">尾页</a>
				</c:if>
				</li>
			</ul>
		</div>
	</div>
</div>
<script src="${pageContext.request.contextPath}/lib/jquery/jquery.js"></script>
	<script>
		function confirmDelete(id){
			if (confirm("确定要删除码？")) {
				alert('发送删除请求，刷新页面（不要异步）');
			}
			return false;
		}
	</script>
	<script type="text/javascript">
		
		if(!(typeof(<%=request.getAttribute("msg") %>)=="object")){
			alert("${msg }")
		}
		function fun(){
			var users = document.getElementsByName("u_user");
			var user = [];
			for(var i = 0;i<users.length;i++){
				if(users[i].checked){
					user.push(users[i].value);
				}
			}
			window.location="UserDelsServlet?user="+user;	
		}
	
	</script>
</body>
</html>